package com.dofast.bt.adapter;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.Resource;
import com.dofast.bt.R;
import com.dofast.bt.base.BaseApplication;
import com.dofast.bt.bean.ArticleBean;
import com.dofast.bt.util.GlideImgManager;
import com.dofast.bt.util.Helper;
import com.dofast.bt.util.Utility;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * username:Created by hsj on 2016/12/8 0008.
 * class：
 * 类描述：文章列表
 */

public class ArticleAdapter extends BaseAdapter {
    private List<ArticleBean> list = new ArrayList<ArticleBean>();


    public ArticleAdapter(List<ArticleBean> list) {
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            convertView = LayoutInflater.from(BaseApplication.getInstance().getApplicationContext()).inflate(R.layout.item_article, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //图片
//        GlideImgManager.glideLoader(BaseApplication.getInstance().getApplicationContext(), list.get(position).getImg_head(), R.mipmap.arcicle_pic_4, R.mipmap.arcicle_pic_4, holder.ivHead, 1);


        Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head_locle()).placeholder(R.mipmap.article_pic_3).into(holder.ivHead);
        //名称
        holder.tvName.setText(list.get(position).getName());
        //内容
//        holder.tvContent.setText(list.get(position).getContent());
        //阅读数
        holder.tvLoveNum.setText(list.get(position).getLoveNum() + "");

        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.iv_head)
        ImageView ivHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.tv_love_num)
        TextView tvLoveNum;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
